# 英雄之力
from tkinter import *
import time
import random
from PIL import ImageTk

# 创建主窗口
root = Tk()
root.title('英雄之力')
root.geometry('460x300+700+300')

hero_list = [['暗裔剑魔', '1.jpg', 180, 100, 150, 75], ['牛头酋长', '2.jpg', 180, 200, 100, 120],
            ['冰晶凤凰', '3.jpg', 270, 120, 180, 175], ['潮汐海灵', '4.jpg', 120, 160, 180, 240],
            ['扭曲树精', '5.jpg', 200, 160, 140, 290], ['迷失之牙', '6.jpg', 220, 160, 180, 190]]

# 定义第一个标签
label = Label(root, width=460, height=300)
label.place(x=0, y=0)

# 定义第二个标签
text = StringVar()
Label(root, text='请点击按钮', font=("Arial, 22"), textvariable=text).place(x=50, y=20)
# 先设置text
text.set("请点击按钮")

# 物理攻击
Label(root, text='物理攻击:', ).place(x=50, y=80)
canvas_a = Canvas(root, width=300, height=22, bg="white")
canvas_a.place(x=110, y=80)
# canvas_a.create_rectangle(0, 0, '260', 22, width=0, fill="grey")
# 魔法防御
Label(root, text='魔法攻击:', ).place(x=50, y=120)
canvas_b = Canvas(root, width=300, height=22, bg="white")
canvas_b.place(x=110, y=120)
# canvas_b.create_rectangle(0, 0, '200', 22, width=0, fill="orange")
# 防御能力
Label(root, text='防御能力:', ).place(x=50, y=160)
canvas_c = Canvas(root, width=300, height=22, bg="white")
canvas_c.place(x=110, y=160)
# canvas_c.create_rectangle(0, 0, '180', 22, width=0, fill="blue")
# 上手难度
Label(root, text='上手难度:', ).place(x=50, y=200)
canvas_d = Canvas(root, width=300, height=22, bg="white")
canvas_d.place(x=110, y=200)
# canvas_d.create_rectangle(0, 0, '280', 22, width=0, fill="green")

# 显示动态进度
def progress():
    # m_a = 170
    # m_b = 100
    # m_c = 220
    # m_d = 250
    # 清空上一次绘制的矩形
    canvas_a.delete("all")
    canvas_b.delete("all")
    canvas_c.delete("all")
    canvas_d.delete("all")
    # 获取随机角色数据
    hero_data = hero_list[random.randint(0, len(hero_list)-1)]
    print(hero_data)
    text.set(hero_data[0])
    img_new = ImageTk.PhotoImage(file="./素材包/LOL/" + hero_data[1])
    label.configure(image = img_new)
    label.image = img_new
    n_a = 0
    n_b = 0
    n_c = 0
    n_d = 0
    for i in range(100):
        n_a += hero_data[2]/100
        n_b += hero_data[3]/100
        n_c += hero_data[4]/100
        n_d += hero_data[5]/100
        canvas_a.create_rectangle(0, 0, n_a, 22, width=0, fill = "grey")
        canvas_b.create_rectangle(0, 0, n_b, 22, width=0, fill = "orange")
        canvas_c.create_rectangle(0, 0, n_c, 22, width=0, fill = "blue")
        canvas_d.create_rectangle(0, 0, n_d, 22, width=0, fill = "green")
        root.update()
        time.sleep(0.02)
        

# 定义按钮
Button(root, text='查看属性', command=progress).place(x=200, y=240)

root.mainloop()




















